package cn.genmer.test.security.thread;

import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;

import java.util.concurrent.Future;

public class AsyncTask {

    public static void main(String[] args) {
        System.out.println("程序开始执行");
        SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
        System.out.println("程序执行结束");
    }

    @Async
    public void asyncTask(){
        System.out.println("@Async修饰的无返回值方法调用");
    }

    @Async
    public Future<String> asyncMethodWithReturnType() {
        System.out.println("@Async修饰的有返回值方法调用");
        try {
            Thread.sleep(5000);
            return new AsyncResult<String>("hello world !!!!");
        } catch (InterruptedException e) {
            //
        }

        return null;
    }
}
